﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace ConDes.Controllers
{
    public class AuthController : Controller
    {
        public ActionResult Index()
        {
            return View("Login");
        }

        public JsonResult Validar(string usuario, string contrasena)
        {
            string usuarioWC = ConfigurationManager.AppSettings["usuario"];
            string contraseña = ConfigurationManager.AppSettings["contrasena"];
            bool resultado = usuario.Equals(usuarioWC) && contrasena.Equals(contraseña);

            if (resultado)
            {
                FormsAuthentication.Initialize();
                FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1, usuario, DateTime.Now, DateTime.Now.AddDays(30), true, @"", FormsAuthentication.FormsCookiePath);
                HttpContext.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(fat)));
            }

            return Json(new { resultado = resultado }, JsonRequestBehavior.AllowGet);
        }
    }
}
